package kgc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class ConfigMange {
    Properties properties = null;
    static ConfigMange configMange = null;

    public ConfigMange(String path){
        properties = new Properties();
        InputStream inputStream = null;
        File file = new File(path);
        try {
            inputStream = new FileInputStream(file);
            properties.load(inputStream);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (inputStream != null){
                    inputStream.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    public static ConfigMange getConfigMange(String path){
        if (configMange == null){
            configMange = new ConfigMange(path);
        }
        return configMange;
    }

    public String getValue(String key){
        if (properties != null){
            if (properties.getProperty(key) != null){
                return properties.getProperty(key);
            }else {
                return key+"对象不存在!";
            }
        }else {
            return "properties对象不存在!";
        }
    }
}
